<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class register extends CI_Controller {

	/**
	 * Index Page for this controller.
	 *
	 * Maps to the following URL
	 * 		http://example.com/index.php/welcome
	 *	- or -  
	 * 		http://example.com/index.php/welcome/index
	 *	- or -
	 * Since this controller is set as the default controller in 
	 * config/routes.php, it's displayed at http://example.com/
	 *
	 * So any other public methods not prefixed with an underscore will
	 * map to /index.php/welcome/<method_name>
	 * @see http://codeigniter.com/user_guide/general/urls.html
	 */
	public function __construct() {
		parent::__construct();
		ini_set('session.cookie_httponly',1); 
		ini_set('session.use_only_cookies',1);	
		$this->load->model('user_class');
	}	 
	public function register_user(){
		$post = $this->input->post();
		$message = $this->user_class->insert($post);
		echo json_encode($message);
	}
	public function chk_email(){
		$post = $this->input->post();
		$data['strEmail']="";
		$user = $this->user_class->chk_email($post);
		$data['qry']=$this->db->last_query();
		if($user!=0){
			$data['strEmail'] = $user['strEmail'];
		}
		echo json_encode($data);
	}	
	public function send_password(){
		$post = $this->input->post();
		$strName = $post['strName'];
		$strPassword =  pw_unhash($post['strKeys']);
		$strAdminEmail = $this->session->userdata('strAdminEmail');
		$strAdminEmailName = $this->session->userdata('strAdminEmailName');
		$strSentPasswordEmail =$this->session->userdata('strSentPasswordEmail');
		
		$message_data = str_replace('$strName',$strName,$strSentPasswordEmail);
		$message_data = str_replace('$strPassword',$strPassword,$message_data);
		$message_data = str_replace('$strAdminEmailName',$strAdminEmailName,$message_data);
		$email_message = $message_data;
				
// 		$config['charset'] = 'utf-8';
//  	$config['wordwrap'] = TRUE;
//  	$config['mailtype'] = 'html';
// 		$config['protocol'] = 'sendmail';
		
//		$config['protocol'] = 'mail';
			
		$this->load->library('email',$config);
		$this->email->from($strAdminEmail, $strAdminEmailName);
		$this->email->to($post['strEmail']);
		$this->email->cc('');
		$this->email->bcc('');
		
		$this->email->subject('[Password - '.date("M d, Y").']');
		$this->email->message($email_message);

		$this->email->send();
		$debug =  $this->email->print_debugger();
		$data['debug'] = $debug;
		$succes = "successfully sent";
		$pos = strpos($debug, $succes);
		if ($pos === false) {
			$data['email'] = 0;
		} else {
			$data['email'] = 1;
		}
						
		echo json_encode($data);
	}
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */